home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2b.lha / p4-1.2b / lib / p4_args.c < prev    next >
C/C++ Source or Header  |  1993-02-06  |  5KB  |  191 lines

  1. /*
  2.  * p4_args.c   Code that looks at the arguments, recognizes any that are
  3.  *             for p4, uses the arguments, and removes them from the
  4.  *             command line args.
  5.  */
  6. #include "p4.h"
  7. #include "p4_sys.h"
  8.  
  9. /* Macro used to see if an arg is not following the correct format. */
  10. #define bad_arg(a)    ( ((a)==NULL) || ((*(a)) == '-') )
  11.  
  12. static char pgm[100];        /* Used to keep argv[0] for the usage cmd. */
  13.  
  14. static P4VOID usage();
  15. static P4VOID print_version_info();
  16. static P4VOID strip_out_args();
  17.  
  18.  
  19. P4VOID process_args(argc, argv)
  20. int *argc;
  21. char **argv;
  22. {
  23.     char *s, **a;
  24.     int c;
  25.  
  26.     /* Put the name of the called program (according to the args) into pgm */
  27.     s = (char *)  rindex(*argv, '/');
  28.     if (s)
  29.     strcpy(pgm, s + 1);
  30.     else
  31.     strcpy(pgm, *argv);
  32.  
  33.     /* Set all command line flags to their default. */
  34.     debug_level = 0;
  35.     remote_debug_level = 0;
  36.     strcpy(bm_outfile, "");
  37.     strcpy(procgroup_file, "procgroup");
  38.     strcpy(local_domain, "");
  39.  
  40.     /* Move to last argument, so that we can go backwards. */
  41.     a = &argv[*argc - 1];
  42.  
  43.     /*
  44.      * Loop backwards through arguments, catching the ones that start with
  45.      * '-'.  Backwards is more efficient when you are stripping things out.
  46.      */
  47.     for (c = (*argc); c > 1; c--, a--)
  48.     {
  49.  
  50.     if (**a != '-')
  51.         continue;
  52.  
  53.     if (!strcmp(*a, "-pg"))
  54.     {
  55.         if (bad_arg(a[1]))
  56.         usage();
  57.         strcpy(procgroup_file, a[1]);
  58.         strip_out_args(a, argc, &c, 2);
  59.         continue;
  60.     }
  61.     if (!strcmp(*a, "-dbg"))
  62.     {
  63.         if (bad_arg(a[1]))
  64.         usage();
  65.         debug_level = atoi(a[1]);
  66.         strip_out_args(a, argc, &c, 2);
  67.         continue;
  68.     }
  69.     if (!strcmp(*a, "-ssport"))
  70.     {
  71.         if (bad_arg(a[1]))
  72.         usage();
  73.         sserver_port = atoi(a[1]);
  74.         strip_out_args(a, argc, &c, 2);
  75.         continue;
  76.     }
  77.     if (!strcmp(*a, "-rdbg"))
  78.     {
  79.         if (bad_arg(a[1]))
  80.         usage();
  81.         remote_debug_level = atoi(a[1]);
  82.         strip_out_args(a, argc, &c, 2);
  83.         continue;
  84.     }
  85.     if (!strcmp(*a, "-gm"))
  86.     {
  87.         if (bad_arg(a[1]))
  88.         usage();
  89.         globmemsize = atoi(a[1]);
  90.         strip_out_args(a, argc, &c, 2);
  91.         continue;
  92.     }
  93.     if (!strcmp(*a, "-dmn"))
  94.     {
  95.         if (bad_arg(a[1]))
  96.         usage();
  97.         strcpy(local_domain, a[1]);
  98.         strip_out_args(a, argc, &c, 2);
  99.         continue;
  100.     }
  101.     if (!strcmp(*a, "-out"))
  102.     {
  103.         if (bad_arg(a[1]))
  104.         usage();
  105.         strcpy(bm_outfile, a[1]);
  106.         strip_out_args(a, argc, &c, 2);
  107.         continue;
  108.     }
  109.     if (!strcmp(*a, "-rout"))
  110.     {
  111.         if (bad_arg(a[1]))
  112.         usage();
  113.         strcpy(rm_outfile_head, a[1]);
  114.         strip_out_args(a, argc, &c, 2);
  115.         continue;
  116.     }
  117.     if (!strcmp(*a, "-p4log"))
  118.     {
  119.         strip_out_args(a, argc, &c, 1);
  120.         logging_flag = TRUE;
  121.         continue;
  122.     }
  123.     if (!strcmp(*a, "-p4version"))
  124.     {
  125.         strip_out_args(a, argc, &c, 1);
  126.         print_version_info();
  127.         continue;
  128.     }
  129.     if (!strcmp(*a, "-?") || !(strcmp(*a, "-help")))
  130.         usage();
  131.     }
  132. }
  133.  
  134. static P4VOID strip_out_args(argv, argc, c, num)
  135. char **argv;
  136. int *argc, *c, num;
  137. {
  138.     char **a;
  139.     int i;
  140.  
  141.     /* Strip out the argument. */
  142.     for (a = argv, i = (*c); i <= *argc; i++, a++)
  143.     *a = (*(a + num));
  144.     (*argc) -= num;
  145. }
  146.  
  147. static P4VOID usage()
  148. {
  149.     print_version_info();
  150.     printf("p4 usage: %s options\n", pgm);
  151.     printf("Valid options:\n");
  152.     printf("\t-help   \tget this message\n");
  153.     printf("\t-pg     \tprocgroup_file\n");
  154.     printf("\t-dbg    \tset debug level\n");
  155.     printf("\t-rdbg   \tset remote debug level\n");
  156.     printf("\t-gm     \tset globmemsize\n");
  157.     printf("\t-dmn    \tdomainname\n");
  158.     printf("\t-out    \tfile \toutput file for master\n");
  159.     printf("\t-rout   \tfile \toutput file prefix for remote masters\n");
  160.     printf("\t-ssport \tport# private port number for secure server \n");
  161.     printf("\t-p4log  \tenable internal p4 logging by alog; only works if p4 made with alog\n");
  162.     printf("\t-p4version \tprint current p4 version number\n");
  163.     printf("\n");
  164.     exit(-1);
  165. }
  166.  
  167. static P4VOID print_version_info()
  168. {
  169.         printf("\n");
  170.         printf("p4 version number:  %s\n",p4_version());
  171.         printf("p4  date compiled:  %s\n",P4_COMPILED_TIME);
  172.         printf("p4   machine type:  %s\n",P4_MACHINE_TYPE);
  173. #ifdef P4_DPRINTFL
  174.         printf("   P4_DPRINTFL is:  on\n");
  175. #else
  176.         printf("   P4_DPRINTFL is:  off\n");
  177. #endif
  178. #ifdef ALOG_TRACE
  179.         printf("    ALOG_TRACE is:  on\n");
  180. #else
  181.         printf("    ALOG_TRACE is:  off\n");
  182. #endif
  183. #if defined(SUN_IPC) || defined(DEC5000_IPC) || defined(RS6000_IPC) || defined(IBM3090_IPC) || \
  184.     defined(HP_IPC)  || defined(TITAN_IPC)   || defined(SGI_IPC)
  185.         printf("      SYSV IPC is:  on\n");
  186. #else
  187.         printf("      SYSV IPC is:  off\n");
  188. #endif
  189.         printf("\n");
  190. }
  191.